interface _CA_ {
    /**
     * 截取数组一部分
     * @param arr 数组
     * @param from 开始位置
     * @param to 结束位置
     * @returns 新数组
     * @description 返回的新数组长度一定是from和to的差值长度，如超出已有数组，则补0。
     */
    part<T>(arr: Array<T>, from: number, to: number): Array<T>;
}
{
    Object.defineProperty(_CA_.prototype, 'part', {
        writable: false,
        configurable: false,
        enumerable: false,
        value: function (arr: Array<any>, from: number, to: number) {
            if (from > to) {
                [from, to] = [to, from];
            }
            if (from === to) { return []; }
            let [f, t] = [from, to];
            if (from < 0) { from = 0; }
            if (to > arr.length) { to = arr.length; }
            const result = arr.slice(from, to);
            if (from === f && to === t) { return result; }

            if (from !== f) {
                for (let i = 0; i < from - f; i++) {
                    result.unshift(0);
                }
            }
            if (to !== t) {
                for (let i = 0; i < t - to; i++) {
                    result.push(0);
                }
            }
            return result;
        }
    });
}
